﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FrameWork.Setting
{

    /// <summary>
    /// 为设定属性编辑提供一般说明
    /// </summary>
    public class SettingPropertyEditorItem : SettingEditorItem
    {

        #region==========属性==========

        /// <summary>
        /// 表示该设定属性编辑项的显示名
        /// </summary>
        public string ShowName { get; private set; }
        /// <summary>
        /// 表示该设定属性编辑项绑定的实例对象
        /// </summary>
        public object LinkeObj { get; private set; }
        /// <summary>
        /// 表示该设定属性编辑项绑定的类型
        /// </summary>
        public Type LinkedType { get; private set; }

        #endregion

        #region========私有变量========

        private SettingPropertyEditor BaseEditor;
        
        #endregion

        #region========公有方法========
        public override bool SaveSetting(SettingOperatorBase SettingOper)
        {
            return SettingOper.OperateSettingFromObject(LinkeObj, LinkedType, false);
        }

        public override bool LoadSetting(SettingOperatorBase SettingOper)
        {
            return SettingOper.OperateSettingFromObject(LinkeObj, LinkedType, true);
        }

        public override bool AcceptSetting()
        {
            //FilePool.ReciveFileSaveDir = BaseEditor.txtRecivePath.Text;
            //FilePool.RequestReSendCount =(int)BaseEditor.nudRetryCount.Value;
            //FilePool.RequestReSendTick = (int)BaseEditor.nudTimeOut.Value;
            //FilePool.BufferSize = (int)BaseEditor.nudBufferSize.Value;
            BaseEditor.AcceptSetting();
            return true;
        }

        public override bool ResetEditor()
        {
            //BaseEditor.txtRecivePath.Text = FilePool.ReciveFileSaveDir;
            //BaseEditor.nudRetryCount.Value = FilePool.RequestReSendCount;
            //BaseEditor.nudTimeOut.Value = FilePool.RequestReSendTick;
            //BaseEditor.nudBufferSize.Value = FilePool.BufferSize;
            BaseEditor.ResetEditor(LinkeObj, LinkedType);
            return true;
        }

        public override bool ResetToDefault()
        {
            return false;
        }

        public override string GetShowName()
        {
            return ShowName;
        }
        #endregion

        #region========构造函数========

        /// <summary>
        /// 初始化设定属性编辑器编辑项的新实例
        /// </summary>
        /// <param name="ShowName">该编辑项的显示名</param>
        /// <param name="Obj">该编辑项关联的对象实例</param>
        /// <param name="Type">该编辑项关联的对象类型</param>
        public SettingPropertyEditorItem(string ShowName,object Obj,Type Type)
        {
            this.Editor = new SettingPropertyEditor();
            this.BaseEditor = (SettingPropertyEditor)Editor;
            this.LinkedType = Type;
            this.LinkeObj = Obj;
            this.ShowName = ShowName;
        }

        #endregion

    }

}
